package com.imavis;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.imavis.video.parse.VideoInfo;
import com.imavis.video.parse.h264.H264Parser;
import com.imavis.video.parse.mpeg4.Mpeg4Parser;

public class ParseTest {

    private static final String PATH = "/home/xiaolifan/test.ts";

    public static void main(String[] args) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("start parse");
                H264Parser parser = new H264Parser();
                byte[] frame = File2byte(PATH);
                VideoInfo videoInfo = parser.parse(frame);
                System.out.println("result: " + videoInfo.getResolution().toString());
            }
        }).start();

    }

    public static byte[] File2byte(String filePath)
    {
        byte[] buffer = null;
        try
        {
            File file = new File(filePath);
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1)
            {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer;
    }
}
